<template>
  <div class="photoinfo-container">
    <h3>{{photoInfo.title}}</h3>
    <p class="subtitle">
        <span>发表时间:{{photoInfo.add_time|dataFormat}}</span>
        <span>点击次数:{{photoInfo.click}}次</span>
    </p>
    <hr>
    <!-- 缩略图区域 -->
    <div class="thumbs">
        <vue-preview :slides="list" class="imgPrev"></vue-preview>
    </div>
    <!-- 图片内容区域 -->
    <div class="content" v-html="photoInfo.content"></div>
    <!-- 评论子组件 -->
    <comment-box :id="id"></comment-box>
  </div>
</template>

<script>
import {Toast} from 'mint-ui'
import comment from '../subcomponents/comment.vue'

export default {
  components: {
      'comment-box':comment
  },
  data(){
      return {
          id:this.$route.params.id,
          photoInfo:[],
          list:[]//缩略图的数组
      }
  },
  created(){
      this.getPhotoInfo()
      this.getThumbs()
  },
  methods:{
    getPhotoInfo(){//获取图片信息
            this.$axios({
            method:'get',
            url:'/api/getimageInfo/'+this.id,
        }).then((response) =>{          //这里使用了ES6的语法
            //console.log(response)       //请求成功返回的数据
            if(response.data.status===0){
                this.photoInfo = response.data.message[0]
            }else{
                Toast('获取图片信息失败！')
            }
        }).catch((error) =>{
            console.log(error)       //请求失败返回的数据
        })
    },
    getThumbs(){//获取缩略图
            this.$axios({
            method:'get',
            url:'/api/getthumimages/'+this.id,
        }).then((response) =>{          //这里使用了ES6的语法
            //console.log(response)       //请求成功返回的数据
            if(response.data.status===0){
                response.data.message.forEach(item => {
                    item.w=600
                    item.h=400
                    item.msrc = item.src
                });
                this.list = response.data.message
            }else{
                Toast('获取缩略图失败！')
            }
        }).catch((error) =>{
            console.log(error)       //请求失败返回的数据
        })
    }
  }
}
</script>

<style lang="scss">
.photoinfo-container{
    padding: 3px;
    h3{
        color: #26a2ff;
        font-size: 15px;
        text-align: 15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size: 13px;
    }
    .content{
        font-size: 13px;
        line-height: 30px;
    }
    .thumbs{
        .imgPrev{
            .my-gallery{
                figure{
                    display: inline-block;
                    margin: 8px;
                }
                img{
                    box-shadow: 0 0 8px #999;
                    height: 100px;
                }
            }
        }
    }
}

</style>
